home *** CD-ROM | disk | FTP | other *** search
Text File | 1987-10-27 | 7.5 KB | 202 lines | [TEXT/CCL ] |
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;Fred-Extensions.Lisp
- ;;
- ;;copyright © 1987, Coral Software Corp
- ;;
- ;;this file contains extensions to Fred the editor.
- ;;
- ;;it can also be used as a source of examples for Fred programming.
-
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;ed-block-selection
- ;;
- ;; This function is used for re-blocking paragraphs of text.
- ;; It doesn't work on code (because it erases pretty printing)
- ;; and it doesn't work on comments (because semi-colons might be moved
- ;; away from the beginning of a line). It's basically good when Fred is
- ;; being used to edit straight text files.
- ;;
- ;; The function first deletes carriage-returns from the selection, and then
- ;; re-inserts them to make all the lines the same length. If there are
- ;; two or more carriage-returns in a row, it takes them as a paragraph break
- ;; and leaves them in place.
- ;;
- ;; The line length is determined by the variable *fred-max-line-width*
- ;;
- ;;
-
-
- ;;bind the blocking command to meta-space
- (def-fred-command
- (:meta #\q)
- ed-block-selection)
-
- ;;define the special variable which holds the line length
- (defvar *fred-max-line-width* 80)
-
- (defobfun (ed-block-selection *fred-window*) (&aux (buf (window-buffer))
- next-char
- prev-char
- new-start
- next-break
- next-line)
- (multiple-value-bind (b e)
- (selection-range)
-
- (unless (eq b e)
- (setq b (make-mark buf (buffer-line-start buf b))
- e (make-mark buf (buffer-line-end buf e) t) ;a backward mark
- new-start (mark-position b))
- (buffer-insert buf (format nil "~% ") e)
- (loop
- (setq new-start (buffer-line-end buf new-start))
- (when (>= new-start (mark-position e)) (return))
- (setq next-char (buffer-char buf (+ new-start 1))
- prev-char (or (eq new-start 0) (buffer-char buf (- new-start 1))))
- (unless (or (eq next-char #\return) (eq prev-char #\return))
- (if (or (eq next-char #\space) (eq prev-char #\space))
- (buffer-delete buf :start new-start :length 1)
- (buffer-char-replace buf #\space new-start)))
- (setq new-start (min (+ new-start 1) (buffer-size buf))))
- (setq new-start (mark-position b))
- (loop
- (when (or (>= new-start (buffer-size buf))
- (and next-break
- (>= next-break (mark-position e))))
- (return))
- (loop
- (setq next-line (buffer-line-end buf new-start)
- next-break (+ new-start *fred-max-line-width*))
- (if (<= next-line next-break)
- (setq new-start (+ next-line 1))
- (return)))
- (setq next-break (buffer-char-pos buf #\space
- :start new-start
- :end next-break
- :from-end t))
- (when next-break
- (buffer-char-replace buf #\return next-break)
- (setq new-start (+ next-break 1)))
- (setq next-break (min (+ new-start *fred-max-line-width*)
- (buffer-size buf))))
- (buffer-delete buf :start e :length 3)
- (kill-mark e)
- (kill-mark b))))
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;ed-delete-forward-whitespace
- ;;
- ;; deletes all the whitespace from the cursor to the next non-whitespace
- ;; character. If there is a selection, the selection is also deleted.
- ;;
-
- ;;define the function
- (defobfun (ed-delete-forward-whitespace *fred-window*) ()
- (multiple-value-bind (b e) (selection-range)
- (if (/= b e) (clear) ;If there is a selection, just kill it.
- (let ((buffer (window-buffer)))
- (buffer-delete buffer :start b
- :end (or (buffer-not-char-pos buffer "
- " :start b)
- (buffer-size buffer)))))))
- ;;bind it to a keystroke in the control-x comtab.
- ;; this means that you invoke the command by typing control-x control-space
- (comtab-set-key *control-x-comtab*
- '(:control #\space)
- 'ed-delete-forward-whitespace)
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;ed-other-window
- ;;
- ;; toggles between the top two fred windows.
- ;; (the listener counts as a fred window.)
- ;;
-
- ;;define the function
- (defobfun (ed-other-window *fred-window*) ()
- (let ((windows (cdr (windows *fred-window*))))
- (if windows
- (ask (car windows) (window-select))
- (ed-beep))))
-
- ;;set it to a keystroke in the control-x comtab.
- ;; this means you type control-x, followed by o (without control) to invoke
- ;; the command
- (comtab-set-key *control-x-comtab*
- #\o
- 'ed-other-window)
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;ed-move-to-comment
- ;;
- ;; moves to a specified column after the end of a line and inserts a
- ;; semi-colon in preparation for inserting comments
- ;;
- ;; If there is already a semi-colon in the line, it just positions the
- ;; cursor after the semi-colon.
- ;;
-
- ;column where comments will be inserted
- (defvar *comment-default-column* 45)
-
- ;used for formatting
- (defvar *string-of-70-spaces*
- " ")
-
- ;;the function itself
- (defobfun (ed-move-to-comment *fred-window*) ()
- (let* ((curs (window-cursor-mark))
- (buf (window-buffer))
- (line-b (buffer-line-start buf curs))
- (line-e (buffer-line-end buf curs))
- (last-semi (buffer-char-pos buf #\;
- :start line-b
- :end line-e
- :from-end t)))
- (if last-semi
- (set-mark curs (+ last-semi 1))
- (progn
- (when (> (buffer-column buf line-e)
- *comment-default-column*)
- (buffer-insert buf #\return line-e)
- (incf line-e))
- (buffer-insert buf
- (subseq *string-of-70-spaces*
- 0
- (- *comment-default-column*
- (buffer-column buf line-e)))
- line-e)
- (setq line-e (buffer-line-end buf line-e))
- (buffer-insert buf #\; line-e)
- (set-mark curs (+ line-e 1))))))
-
- ;;define a fred command for calling the function
- (def-fred-command (:meta #\;) ed-move-to-comment)
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;
- ;; redefine two keystrokes, so that control forward-arrow and back-arrow
- ;; can be used for moving forward and backward by Lisp expression.
-
-
- (def-fred-command (:control #\backarrow)
- ccl::ed-backward-sexp)
-
- (def-fred-command (:control #\forwardarrow)
- ccl::ed-forward-sexp)
-
-
- (provide 'fred-extensions)
- (pushnew :fred-extensions *features*)